package com.yoomiito.app.ui.anyview.order;

import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.yoomiito.app.R;
import com.yoomiito.app.interf.BaseOrderGoodsView;
import com.yoomiito.app.model.bean.AppInterfaceInfo;
import com.yoomiito.app.model.bean.GoodsDetail;
import com.yoomiito.app.utils.AllUtils;
import com.yoomiito.app.utils.ImageLoader;
import com.yoomiito.app.utils.L;
import com.yoomiito.app.utils.SpannableUtils;
import com.yoomiito.app.widget.NumControlView;

/**
 * 确认订单------商品信息 数量 优米抵扣
 */
public class BaoPinPinOrderGoodsView extends BaseOrderGoodsView {

    private int mGoodsSize = 1;

    public BaoPinPinOrderGoodsView(Context context, GoodsDetail detail, AppInterfaceInfo appInterfaceInfo) {
        super(context,detail,appInterfaceInfo);
    }

    @Override
    public int getView() {
        return R.layout.view_youpin_order_goods;
    }

    @Override
    public void initView() {
        mGoodsSize = 1;
        ImageView goodsIv = findViewById(R.id.item_order_goods_iv);
        TextView goodsTitle = findViewById(R.id.item_order_goods_title);
        TextView goodsPrice = findViewById(R.id.item_order_goods_price);
        NumControlView numControlView = findViewById(R.id.num_control_view);

        FrameLayout frameLayout = findViewById(R.id.frameLayout);
        frameLayout.setVisibility(View.GONE);

        ImageLoader.getInstance().into(mContext,mGoodsDetail.getPict_url(),goodsIv);
        goodsTitle.setText(mGoodsDetail.getTitle());
        goodsPrice.setText("¥" + mGoodsDetail.getSalePrice());

        numControlView.setListener(num -> {
            mGoodsSize = num;
            changeMoney();
        });
        numControlView.addOnInputNumChangeListener(num -> {
            mGoodsSize = num;
            changeMoney();
        });

        changeMoney();
    }

    private void changeMoney() {
        mGoodsTotalPrice = AllUtils.priceMul_2(mGoodsDetail.getSalePrice(), mGoodsSize);
        String s = "共" + mGoodsSize + "件 合计¥" + mGoodsTotalPrice;
        int p = s.indexOf("¥");
        spanText = SpannableUtils.getSizeAndPriceText(s, R.color.color_FF035B, p, s.length(), p, p + 1);
        if (mOnShowInfoListener!=null){
            mOnShowInfoListener.onShow(spanText,mGoodsSize,0);
        }
    }
}
